/**
 * 对象工具函数
 */

/**
 * 深度克隆对象
 * @param obj - 要克隆的对象
 * @returns 对象的深度克隆副本
 */
export function deepClone<T>(obj: T): T {
  if (obj === null || typeof obj !== 'object') {
    return obj;
  }

  if (Array.isArray(obj)) {
    return obj.map(item => deepClone(item)) as unknown as T;
  }

  return Object.keys(obj).reduce((result, key) => {
    return {
      ...result,
      [key]: deepClone((obj as Record<string, any>)[key])
    };
  }, {}) as T;
}

/**
 * 从对象中选取指定的属性
 * @param obj - 源对象
 * @param keys - 要选取的键数组
 * @returns 只包含指定属性的新对象
 */
export function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {
  return keys.reduce((result, key) => {
    if (key in obj) {
      result[key] = obj[key];
    }
    return result;
  }, {} as Pick<T, K>);
}

/**
 * 从对象中排除指定的属性
 * @param obj - 源对象
 * @param keys - 要排除的键数组
 * @returns 不包含指定属性的新对象
 */
export function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {
  return Object.keys(obj)
    .filter(key => !keys.includes(key as K))
    .reduce((result, key) => {
      result[key as keyof Omit<T, K>] = obj[key as keyof T] as any;
      return result;
    }, {} as Omit<T, K>);
} 